﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using ANZ_AIM_FRAMEWORK;
using System.Configuration;

namespace ANZ_AIM_DAL
{


    public class DBHelper
    {
        static string DBPath = ConfigurationManager.AppSettings["DBPath"];
        static string LogDBPath = ConfigurationManager.AppSettings["LogDBPath"];
        static string PwdDB = ConfigurationManager.AppSettings["PwdDB"];
        public static string GenExcelConnStr(string filename)
        {
            if (string.IsNullOrEmpty(filename))
                return null;

            string excelFilename = @filename;
            string excelConnStr =
                string.Format("Data Source= {0};Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;", excelFilename);
            return excelConnStr;
        }

        public static string GenAccessConnStr(string filename)
        {
            if (string.IsNullOrEmpty(filename))
                return null;

            string accessFilename = @filename;
            string accessConnStr =
                string.Format("Data Source= {0};Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info = false;", accessFilename);
            return accessConnStr;
        }

        public static string GenDbaseConnStr(string filename)
        {
            if (string.IsNullOrEmpty(filename))
                return null;

            string dbaseFilename = @filename;
            string dbaseConnStr =
                string.Format("Data Source= {0};Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=dBASE IV;", dbaseFilename);
            return dbaseConnStr;
        }

        public static string GenVfpConnStr(string folderPath)
        {
            if (string.IsNullOrEmpty(folderPath))
                return null;

            string dbaseConnStr =
                string.Format("Data Source= {0};Provider=VFPOLEDB.1;", folderPath);
            return dbaseConnStr;
        }

        /// <summary>
        /// Get connection string for Main.mdb.
        /// </summary>
        /// <returns>Full connection String with password.</returns>
        public static string GetMainMdbConnectionString()
        {
            AESHelper aes = new AESHelper();
            string dbaseConnStr = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Database Password={1}", DBPath, aes.DecryptToString(PwdDB));
            return dbaseConnStr;
        }


        public static string GetLogConnectionString() {
            AESHelper aes = new AESHelper();
            string dbaseConnStr = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Database Password={1}", LogDBPath, aes.DecryptToString(PwdDB));
            return dbaseConnStr;
        }
        public static string GetMainMdbConnectionStringWithoutPwd()
        {
         
            string dbaseConnStr = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", DBPath);
            return dbaseConnStr;
        }
    
    }
}

